$(function () {

    $.ajax({
        url: "http://ehr.faw.cn/portal/perinfo/getAllPersonInfoPC?EMPLID=&cache=" + t(36),
        type: 'GET',
        //data: '{"name":"snow","gender":0}',
        dataType: 'json',
        xhrFields: {
            withCredentials: true
        },
        beforeSend: function (xhr) {
            xhr.withCredentials = true
        },
        success: function (data) { // http code 200
            if (data.status === '0') {
                console.info(data);
                $("#NAME").val(data.data.BasicPersonInfo.NAME);
                $("#HIGHEST_EDUC_DESCR").val(data.data.BasicPersonInfo.HIGHEST_EDUC_DESCR);
                $("#BUSINESS_UNIT_DESC").val(data.data.BasicPersonInfo.BUSINESS_UNIT_DESC);
                $("#DEPTNAME").val(data.data.BasicPersonInfo.DEPTNAME);
                $("#POSITION_NBR_DESCR").val(data.data.BasicPersonInfo.POSITION_NBR_DESCR);
                $("#CST_POSITION_TYPED").val(data.data.BasicPersonInfo.CST_POSITION_TYPED);
                //$("#DESCR1").val(data.data.DESCR1);
                //$("#DESCR100").val(data.data.DESCR100);
            } else {
                toastr.error(data.message, '获取个人信息错误', {
                    timeOut: 3000,
                    positionClass: 'toast-top-left',
                    closeButton: true,
                });
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            switch (XMLHttpRequest.status) {
                case 401:
                    break;
                case 404:
                    break;
                case 500:
                    break;
            }
        }
    });

    let myDate = new Date();
    let year = myDate.getFullYear();
    let month = myDate.getMonth() + 1;

    let endyear = year;
    let endmonth = month;
    if (endmonth == 12) {
        endmonth = 1;
        endyear = endyear + 1;
    }else {
        endmonth = endmonth + 1;
    }

    $.ajax({
        url: "http://ehr.faw.cn/portal/salary/getSalary",
        type: 'POST',
        data: JSON.stringify({
            BGNDATE: (year - 2) + "-" + (month < 10 ? "0" + month : month),
            ENDDATE: endyear + "-" + (endmonth < 10 ? "0" + endmonth : endmonth),
            page: 1
        }),
        xhrFields: {
            withCredentials: true
        },
        headers: {'Content-Type': 'application/json;charset=UTF-8'},
        success: function (data) { // http code 200
            if (data.status === '0') {
                console.info(data);
                $('#salary1').bootstrapTable('load', data.data.salaryList);

                let xAxisData = [];
                let seriesData = [];
                for (let i = 0; i < data.data.salaryList.length; i++) {
                    let row = data.data.salaryList[data.data.salaryList.length - i - 1];
                    xAxisData.push(row.CAL_PRD_ID);
                    seriesData.push(row.CST_NUM_129);
                }


                let myChart = echarts.init(document.getElementById('echart1'));
                let option = {
                    title: {
                        text: "近2年月实得曲线",
                    },
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'cross',
                        }
                    },
                    xAxis: {
                        type: 'category',
                        boundaryGap: false,
                        data: xAxisData,
                    },
                    yAxis: {
                        type: 'value',
                    },
                    series: {
                        type: 'line',
                        data: seriesData,
                        connectNulls: true,
                        label: {
                            show: true,
                        },
                    },
                };
                myChart.setOption(option, true);

            } else {
                toastr.error(data.message, '获取月薪酬信息错误', {
                    timeOut: 3000,
                    positionClass: 'toast-top-left',
                    closeButton: true,
                });
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            switch (XMLHttpRequest.status) {
                case 401:
                    break;
                case 404:
                    break;
                case 500:
                    break;
            }
        }
    });

    $.ajax({
        url: "http://ehr.faw.cn/portal/salary/getYearSalary",
        type: 'POST',
        xhrFields: {
            withCredentials: true
        },
        success: function (data) { // http code 200
            if (data.status === '0') {
                console.info(data);
                $('#salary2').bootstrapTable('load', data.data);

                let xAxisData = [];
                let seriesData = [];
                for (let i = 0; i < data.data.length; i++) {
                    let row = data.data[i];
                    xAxisData.push(row.YEAR);
                    seriesData.push(row.YEARSALARY);
                }


                let myChart = echarts.init(document.getElementById('echart2'));
                let option = {
                    title: {
                        text: "近5年实得曲线",
                    },
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'cross',
                        }
                    },
                    xAxis: {
                        type: 'category',
                        boundaryGap: false,
                        data: xAxisData,
                    },
                    yAxis: {
                        type: 'value',
                    },
                    series: {
                        type: 'line',
                        data: seriesData,
                        connectNulls: true,
                        label: {
                            show: true,
                        },
                    },
                };
                myChart.setOption(option, true);

            } else {
                toastr.error(data.message, '获取年薪酬信息错误', {
                    timeOut: 3000,
                    positionClass: 'toast-top-left',
                    closeButton: true,
                });
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            switch (XMLHttpRequest.status) {
                case 401:
                    break;
                case 404:
                    break;
                case 500:
                    break;
            }
        }
    });
});

function t(e) {
    for (var t = ""; t.length < e; t += Math.random().toString(36).substr(2))
        ;
    return t.substr(0, e)
}
